import { defineStore } from "pinia"

export const useUserStore = defineStore("user", {
	state: () => ({
		user: {
			isLogin: false, //是否登录
			info: {} //用户信息
		},
		token: JSON.parse(localStorage.getItem("token") as any)
			? JSON.parse(localStorage.getItem("token") as any)
			: ""
	}),
	getters: {},
	actions: {
		/**设置用户信息 */
		setUser(info: Record<string, any>) {
			this.user.info = { ...info }
		},
		/**设置token */
		setToken(token: string) {
			this.token = token
			localStorage.setItem("token", JSON.stringify(token))
		},
		/**删除token */
		removeToken() {
			this.token = ""
			localStorage.removeItem("token")
		}
	}
})
